package config

import (
	"flag"
	"fmt"
	"gitee.com/lxx_23/lxx-go-fun/utils"
	"os"
	"path"
)

type ConfigServer struct {
	Port   int    `mapstructure:"port" yaml:"port" json:"port"`
	Prefix string `mapstructure:"prefix" yaml:"prefix" json:"prefix"`
}

type ProjectConfig struct {
	Env    string       `mapstructure:"env" yaml:"env" json:"env"`
	Name   string       `mapstructure:"name" yaml:"name" json:"name"`
	Server ConfigServer `mapstructure:"server" yaml:"server" json:"server"`
}

var Config *ProjectConfig

func init() {
	p, err := os.Getwd()
	if err != nil {
		p = "."
	}

	// 设置环境
	env := flag.String("env", "dev", "运行时环境")
	flag.Parse()

	utils.ReadConfig(path.Join(p, fmt.Sprintf("config/config.%s.yaml", *env)), &Config)
}
